package com.example.design.patterns.geekbang.行为型.策略模式.经典模式;

import java.util.HashMap;
import java.util.Map;

/**
 * 策略创建: 工厂模式创建一组策略
 * 注意: 适用于策略对象无状态
 */
public class StrategyNoStateFactory {
    private static final Map<String, Strategy> strategies = new HashMap<>();

    static {
        strategies.put("A", new ConcreteStrategyA());
        strategies.put("B", new ConcreteStrategyB());
    }

    public static Strategy getStrategy(String type) {
        if (type == null || type.isEmpty()) {
            throw new IllegalArgumentException("type should not be empty.");
        }
        return strategies.get(type);
    }
}